package jmotioncapture.camera;

import java.util.Vector;

public class FrameSet {

	private Vector<Frame> frames;

	public FrameSet() {
		frames = new Vector<Frame>(1000, 200);
	}

	public FrameSet(Vector<Frame> frames) {
		this.frames = frames;
	}

	public FrameSet getLastFramesByNumber(int numberOfFrame) {
		return getLastFramesByNumber(numberOfFrame, 0);
	}

	public FrameSet getLastFramesByNumber(int numberOfFrame, int skip) {
		return framesBetween(frames.size() - 1 - numberOfFrame,
				frames.size() - 1, skip);
	}

	public FrameSet framesBetween(int i, int j, int skip) {
		FrameSet result = new FrameSet();

		if(j > frames.size())
			j = frames.size() - 1;
		
		for (int k = i; k <= j; k = k + 1 + skip)
			result.addFrame(frames.elementAt(k));

		return result;
	}

	public void addFrame(Frame frame) {
		frames.add(frame);
	}

	public Frame firstFrame() {
		return frames.firstElement();
	}

	public Frame lastFrame() {
		return frames.lastElement();
	}

	public Frame frameAt(int i) {
		return frames.elementAt(i);
	}

	public int size() {
		return frames.size();
	}

	public void clear() {
		frames.removeAllElements();
	}

}
